#ifndef _L_SCENE_OBJ_120130_H
#define _L_SCENE_OBJ_120130_H

#include <ltypes.h>
#include <lmacros.h>
#include <ltriMesh.h>
#include <lbvTree.h>
#include <lcollisionResult.h>

#include <vector>

LLIB_BEGIN
namespace geom {

/* The scene object class */
template <typename BVTree_t>
class SceneObj {
public:
    /* The default constructor */
    SceneObj() {}

    /* Initialize the scene object by input vertex and triangle data,
     * the mesh and bvh will be built.
     */
    void Init( std::vector<Vec3f>& vertexList, std::vector<Vec3i>& faceVertexIndexList);

    /* Update BVTree structor */
    void UpdateTree();

    /* Get the reference of TriMesh */
    inline TriMesh& GetTriMesh() { return _mesh; }

    /* Get the reference of Collision */
    inline std::vector<Int32>& GetCollision() { return _collision; }

    /* Check the collisions between two objects,
     * it will exclude self collision check, of cause.
     */
    static void CollisionDetect(SceneObj& first, SceneObj& second);
    inline void CollisionDetect(SceneObj& another) { CollisionDetect(*this, another); }

    /* Check the self collision on current object */
    static void SelfCollisonDetect(SceneObj& obj);
    inline void SelfCollisonDetect() { SelfCollisonDetect(*this); }

    /* Collision response */
    static void CollisionResponse(SceneObj& obj);
    inline void CollisionResponse() { CollisionResponse(*this); }

private:
    /* The scene object triangle mesh data */
    TriMesh     _mesh;
    /* The scene object bounding volume hierarchy */
    BVTree_t    _tree;
    /* The collision result collector */
    collision::CollisionResult _cr;
    /* The collision flag for every triangle */
    std::vector<Int32> _collision;

};

} // end of namespace geom
LLIB_END

#include "_lsceneObj_120130.hpp"

#endif
